import org.jsoup.*;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.sqlite.*;
import java.io.*;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

class RecupGenre {
	
	public static void main(String[] args) throws Exception{
		try{
			Class.forName("org.sqlite.JDBC");
		} catch(ClassNotFoundException e){System.out.println("La classe demandée n'a pas été trouvée");}
		Connection genreConnect = Jsoup.connect("http://mangafox.me/search.php")
									.timeout(30000);
		Document mangaSearch = new Document("");
		Boolean status = false;
		try{
			Document mangaSearch0 = genreConnect.get();
			mangaSearch=mangaSearch0;
			status = true;
		} catch(IOException e){System.out.println("Impossible de récupérer la page");}
		
		java.sql.Connection dBConnect =	DriverManager.getConnection("jdbc:sqlite:mangadb.sqlite"); 
		PreparedStatement stat = dBConnect.prepareStatement("insert or ignore into genre values (?)");
		if(status) {
			Elements genres = mangaSearch.getElementById("genres").getElementsByTag("label");
			
			for (Element genre : genres){
				//System.out.println("Les genres trouvés sont "+genre.text());
				stat.setString(1, genre.text());
				stat.addBatch();
			}
			stat.executeBatch();
		}
	}
}